<template>
  <div id="inventoryTask">
    <Filters
      block
      :form="searchForm"
      :filterData="filterData"
      @confirm="changePage(1)"
    />
    <div class="container">
      <DataTable
        rowKey="taskId"
        :tableData="Data"
        :tableColumn="tableColumn"
        :pageConfig="pageConfig"
        @refresh="getList"
      />
    </div>
  </div>
</template>

<script lang="ts">
import { Component, Vue, Watch } from 'vue-property-decorator';

@Component
export default class inventoryTask extends Vue {
  searchForm: any = {
    detailState: undefined,
    word: '',
    date: []
  };
  btns: any[] = [
    {
      label: '新增任务',
      icon: 'add',
      callback: () => this.$router.push('/allot/task/edit')
    }
  ];
  get filterData () {
    return {
      detailState: {
        label: '任务状态',
        type: 'select',
        template: {
          placeholder: '请选择状态',
          clearable: true,
          filterable: true,
          options: [
            {
              label: '全部',
              value: ''
            },
            {
              label: '进行中',
              value: 'DWC'
            },
            // {
            //   label: '待提交',
            //   value: 'DTJ'
            // },
            // {
            //   label: '待初审核',
            //   value: 'DSH'
            // },
            {
              label: '待终审核',
              value: 'DZH'
            },
            {
              label: '已完成',
              value: 'YWC'
            },
            {
              label: '已驳回',
              value: 'BH'
            }
          ]
        }
      },
      date: {
        label: '完成时限',
        type: 'daterange',
        template: {
          clearable: true
        }
      },
      word: {
        label: '项目名称',
        type: 'input',
        template: {
          placeholder: '项目名称',
          clearable: true
        }
      }
    };
  }
  Data: any[] = [];
  tableColumn: any = {
    taskName: {
      label: '任务名称',
      minWidth: 120
    },
    itemsName: {
      label: '项目名称',
      minWidth: 120
    },
    wcUserName: {
      label: '姓名',
      minWidth: 120
    },
    okTime: {
      label: '完成时限',
      minWidth: 100
    },
    wcTime: {
      label: '实际完成时间',
      minWidth: 100
    },
    detailState: {
      label: '任务状态',
      minWidth: 100,
      map: {
        'DWC': '进行中',
        'DTJ': '待提交',
        'DSH': '待初审核',
        'DZH': '待终审核',
        'YWC': '已完成',
        'BH': '已驳回'
      }
    },
    action: {
      label: '操作',
      width: 230,
      template: [
        {
            tag: 'router-link',
            text: '任务反馈',
            path: '/allot/inventoryTask/taskView',
            query: {
                _alias: 'edit',
                taskDetailId: ''
            },
            show: (row: any) => ['DWC', 'DTJ'].includes(row.detailState)
        },
        {
            tag: 'router-link',
            text: '详情',
            path: '/allot/inventoryTask/taskView',
            query: {
                _alias: 'detail',
                taskDetailId: ''
            },
            show: (row: any) => ['YBH', 'DSH', 'YWC', 'BH', 'DZH'].includes(row.detailState)
        },
        // {
        //     tag: 'router-link',
        //     text: '审核',
        //     path: '/allot/inventoryTask/taskView',
        //     query: {
        //         _alias: 'detail',
        //         taskDetailId: '',
        //         type: 'check'
        //     },
        //     show: (row: any) => ['DSH'].includes(row.state)
        // },
        {
            tag: 'router-link',
            text: '重新提交',
            path: '/allot/inventoryTask/taskView',
            query: {
                _alias: 'edit',
                taskDetailId: ''
            },
            show: (row: any) => row.detailState === 'BH'
        }
      ]
    }
  };
  pageConfig: any = {
    current: 1,
    total: 10,
    pageSize: 10,
    onChange: this.changePage
  };

  get taskId () {
    return this.$route.query.taskId
  }

  init () {
    this.getList()
  }
  getSearchForm () {
    let { searchForm } = this;
    let { current, pageSize } = this.pageConfig
    let form = Object.assign({ page: current, size: pageSize}, searchForm);
    let [ startTime, endTime ] = this.$util.formatDate(form.date)
    Object.assign(form, {
        startTime,
        endTime
    });
    delete form.date
    return form;
  }
  getList () {
    let data = this.getSearchForm()
    this.$api.countingRoleTaskMonitorListFetch(data).then((res: any) => {
      this.Data = res.data.records;
      this.pageConfig.total = res.data.total;
      if (!this.Data.length && this.pageConfig.current > 1) {
        --this.pageConfig.current;
        this.getList();
      }
    });
  }
  changePage (val: number) {
    this.pageConfig.current = val;
    this.getList();
  }
  searchHandle () {
    this.pageConfig.current = 1;
    this.getList();
  }
  delHandle ({ adminId }: any) {
    let data = { adminId };
    this.$api.adminDeleteFetch(data).then((res: any) => {
      this.$message.success('删除成功');
      this.getList();
    });
  }
  changeStatus (row: any, index: number) {
    let { adminId, status } = row;
    this.$api
      .adminStatusFetch({ adminId, status: !status })
      .then((res: any) => {
        this.$message.success(`${status ? '冻结' : '正常'}成功`);
        this.getList();
      });
  }
}
</script>

<style lang="scss">
</style>
